﻿#region Namespace References

using System;
using DynConDevCorp.OpenArch.SmartData.BillingDemo1.ApplicationBusinessObjects;
using DynConDevCorp.OpenArch.SmartData.Core;
using DynConDevCorp.OpenArch.SmartData.Interfaces.Attributes;
using DynConDevCorp.OpenArch.SmartData.WinForms;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.BillingDemo1.SmartUIControls
{
    public partial class ProductSummaryControl : SmartEntityControl
    {
      #region Constructors

        public ProductSummaryControl()
        {
            InitializeComponent();
            bmcEntity.BoundEntityChanged += bmcEntity_BoundEntityChanged;  
            Product = new SmartEntityLink<Product>();
            Product.LinkedEntityChanged += Product_LinkedEntityChanged;
        }

        #endregion

        #region Public Instance Properties

        [AutoField]
        public SmartEntityLink<Product> Product { get; set; }

        #endregion

        #region Public Instance Methods

        private void bmcEntity_BoundEntityChanged(object sender, EventArgs e)
        {
            Product boundProduct = (Product) bmcEntity.BoundEntity;
            Product.LinkedEntity = boundProduct;
        }

        private void Product_LinkedEntityChanged(object sender, EventArgs e)
        {
            bmcProducts.BoundEntity = Product.LinkedEntity;
        }

        #endregion
    }
}